<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php echo $this->Facebook->html(); ?>
<head>

    <?php echo $this->Html->charset(); ?>

    <title>
        <?php echo $title_for_layout; ?>
    </title>

    <meta name="viewport" content="width=device-width, initial-scale =1.0">
        <meta name="keywords" content="Tattlr,Twitter,CoolSoft">
            <meta name ="author" content ="CoolSoft2012">

                <?php
                # Import javascript and css files.
                echo $this->Html->script(array('jquery-1.7.2.min',
                    'jquery-ui-1.8.19.custom.min',
                    'bootstrap.min'));
                echo $this->Html->css(array('jquery-ui-1.8.19.custom.css'));
                echo $this->Html->meta('icon');

                # Fetch the imported files.
                echo $this->fetch('meta');
                echo $this->fetch('css');
                echo $this->fetch('script');
                ?>

                <!-- Le styles -->
                <style type="text/css">
                    body {
                        padding-top: 60px;
                        padding-bottom: 40px;
                    }
					.act{
                        -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
                        -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
                        box-shadow:inset 0px 1px 0px 0px #ffffff;
                        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #E2E2E2), color-stop(1, #B8B8B8) );
                        background:-moz-linear-gradient( center top, #5ac5fa 5%, #3669c2 100% );
                        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5ac5fa', endColorstr='#3669c2');
                        background-color:#5ac5fa;
                        -moz-border-radius:6px;
                        -webkit-border-radius:6px;
                        border-radius:6px;
                        border:1px solid #4a569e;
                        display:inline-block;

                        font-family:arial;

                        font-weight:bold;

                        padding:6px 12px;
                        text-decoration:none;
                    }
                    .act1{
                        -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
                        -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
                        box-shadow:inset 0px 1px 0px 0px #ffffff;
                        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #4869AF), color-stop(1, #083AB9) );
                        background:-moz-linear-gradient( center top, #5ac5fa 5%, #3669c2 100% );
                        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5ac5fa', endColorstr='#3669c2');
                        background-color:#5ac5fa;
                        -moz-border-radius:6px;
                        -webkit-border-radius:6px;
                        border-radius:6px;
                        border:1px solid #4a569e;
                        display:inline-block;

                        font-family:arial;

                        font-weight:bold;

                        padding:6px 12px;
                        text-decoration:none;
                    }
                </style>
<!--<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">-->
<?php echo $this->Html->css('bootstrap.min'); ?>
                </head>

                <body>
                    <div class="navbar navbar-fixed-top">
                        <div class="navbar-inner">
                            <div class="container-fluid">
                                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </a><!--btn-navbar-->
                                <a class="brand" href="http://tattlr.com">Tattlr</a>
                                <div class="nav-collapse">
                                    <ul class="nav">
                                        <li><a href="#" id = "dash"><i  class ="icon-home icon-white"></i> Dashboard</a></li>
                                        <li><a href="#" id="home">Home Timeline</a></li>
                                        <li><a href="#" id="followers">View followers</a></li>
                                        <li><a href="/Tweets">Search</a></li>
                                        <?php if ($ad == 0) { ?>
                                            <li><a href="/tasks/viewAll">Tasks</a></li>
                                        <?php } ?>		
                                        <li><a href="/FutureDms/">View DMs</a></li>
                                        <li><a href="/FutureTweets">FutureTweets</a></li>
                                        <li><a href="/events">Events</a></li>

                                        <?php if ($ad == 1) { ?>
                                            <li><a href="/tattlraccounts/">Admin</a></li>
                                        <?php } ?>
                                        <li><a href="/Users/logout">Logout</a></li>
                                        <li><a href="/tattlraccounts/db">.</a></li>
                                        <li><?php
                                        echo $this->Facebook->login(array(
                                            'redirect' => array('controller' => 'users', 'action' => 'fb_connect'),
                                            'label' => 'Facebook Connect'));
                                        ?></li>									
                                    </ul>
                                </div> 
                            </div><!--container-->
                        </div><!--.navbar-inner-->
                    </div><!--navbar-->
                    <div class ="container-fluid2">
                        <div class ="row-fluid">
                            <div class ="span3">
                                <?php echo $this->Html->script('jquery-1.4.2.min.js'); ?>
                                <?php echo $this->Html->script('jquery-ui-1.8.4.custom.min.js'); ?>
                                <?php echo $this->Html->css('start/jquery-ui-1.8.4.custom.css'); ?>
                                <head>
                                    <script type="text/javascript">
                                        function displayResult()
                                        {
                                            var phpLogin = document.getElementById("TweetText").value ;
                                            var num = 140 - phpLogin.length;
                                            var link = phpLogin.search("http");
                                            document.getElementById("x").innerHTML = num;
                                            var check = isReply();
                                            document.getElementById("x").style.color = "#268613";
                                            if(num==140){
                                                document.getElementById("x").style.color = "#E41212";
                                            }
                                            if(num < 0){
                                                document.getElementById("TweetButton").disabled = true;
                                                document.getElementById("x").style.color = "#E41212";
                                            }
                                            else{
                                                if(check == true){
                                                    $('#CancelReply').show(500);
                                                    var empty = CheckReply();
                                                    document.getElementById("TweetButton").disabled = true;
                                                    if(empty == true){
                                                        document.getElementById("TweetButton").disabled = false;
                                                    }
                                                }else{
                                                    document.getElementById("TweetButton").disabled = true;
                                                    for(var i = 0;i < phpLogin.length;i++){
                                                        if(phpLogin.charAt(i)!=" "){
                                                            document.getElementById("TweetButton").disabled = false;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            if(link > -1){
                                                document.getElementById("TweetButton").disabled = false;
                                            }			
                                        }

                                    </script>
                                    <script type="text/javascript">
                                        function CheckReply(){
                                            var check = document.getElementById("ReplyName").value;
                                            var text = document.getElementById("TweetText").value;
                                            for(var i = check.length;i < text.length ;i++){
                                                if(text.charAt(i)!=' '){
                                                    return true;
                                                }
                                            }
                                            return false;
                                        }
                                        function ahmed(){
                                            $.post("/Tweets/test");
                                        }
                                    </script>
                                    <script type="text/javascript">
                                        function isReply(){
                                            if(document.getElementById("ReplyName").value!= ''){
                                                var check = document.getElementById("ReplyName").value;
                                                var name = (document.getElementById("TweetText").value).split(' ');
                                                if(name[0].length == check.length){
                                                    for(var i = 0;i < check.length ;i++){
                                                        if(check.charAt(i)!=name[0].charAt(i)){
                                                            $('#CancelReply').hide(3000);
                                                            return false;
                                                        }
                                                    }
                                                    return true;
                                                }
                                            }
                                            $('#CancelReply').hide(3000);
                                            return false;
                                        }
                                    </script>
                                    <script type="text/javascript">
                                        function SetReply(ReplyName,ReplyID){
                                            document.getElementById("ReplyName").value = ReplyName;
                                            document.getElementById("ReplyID").value = ReplyID;
                                            document.getElementById("TweetText").value = ReplyName;
                                            displayResult();
                                        }
                                    </script>
                                    <script type="text/javascript">
                                        function Cancel(){
                                            document.getElementById("ReplyName").value = '';
                                            document.getElementById("ReplyID").value = '';
                                            displayResult();
                                            $('#CancelReply').hide(3000);
                                        }
                                        function send(url){
                                            var text = document.getElementById("TweetText").value;
                                            var replyname = document.getElementById("ReplyName").value;
                                            var replyid = document.getElementById("ReplyID").value ;
                                            var image = document.getElementById("image").value ;
                                            document.getElementById("Test").style.color = "red" ;
                                            $.post(url,{ Text: text , ReplyName : replyname , ReplyId : replyid , image:image},
                                            function(data) {
                                                document.getElementById("Test").innerHTML = data;
                                                $('#Test').fadeOut();
                                                $('#Test').stop();
                                                $('#Test').fadeIn().fadeOut(7000);
                                                if(data.search("Tweet was added Successfully")>-1){
                                                    document.getElementById("Test").style.color = "green" ;
                                                    document.getElementById("TweetText").value = '';
                                                    document.getElementById("image").value = null;
                                                    Cancel();
                                                    displayResult();
                                                }
                                            },"html"
                                        );
                                        }
                                    </script>
                                    <script type="text/javascript">
                                        $(window).load(function () {
                                            $('#CancelReply').hide();
                                            $('#Test').hide();		
                                        });
                                    </script>
                                    <script>
                                        $(function ()
                                        { $("#CancelReply").popover({title : "Cancel Reply",content: "If you want to send this as a normal tweet click me then click Tweet :)"});
                                        });
                                    </script>
                                </head>
                                <br />
                                <style type="text/css">
                                    .tweetbutton:enabled {
                                        -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #5ac5fa), color-stop(1, #3669c2) );
                                        background:-moz-linear-gradient( center top, #5ac5fa 5%, #3669c2 100% );
                                        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5ac5fa', endColorstr='#3669c2');
                                        background-color:#5ac5fa;
                                        -moz-border-radius:6px;
                                        -webkit-border-radius:6px;
                                        border-radius:6px;
                                        border:1px solid #4a569e;
                                        display:inline-block;
                                        color:#ffffff;
                                        font-family:arial;
                                        font-size:15px;
                                        font-weight:bold;
                                        float: right;
                                        padding:6px 24px;
                                        text-decoration:none;
                                    }.tweetbutton:disabled{
                                        -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f0f0f0), color-stop(1, #f0f0f0) );
                                        background:-moz-linear-gradient( center top, #f0f0f0 5%, #f0f0f0 100% );
                                        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f0f0f0', endColorstr='#f0f0f0');
                                        background-color:#000000;
                                        -moz-border-radius:6px;
                                        -webkit-border-radius:6px;
                                        border-radius:6px;
                                        border:1px solid #4a569e;
                                        display:inline-block;
                                        color:#b8b8b8;
                                        font-family:arial;
                                        font-size:15px;
                                        font-weight:bold;
                                        float: right;
                                        padding:6px 24px;
                                        text-decoration:none;
                                    }.tweetbutton:hover:enabled {
                                        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #3669c2), color-stop(1, #5ac5fa) );
                                        background:-moz-linear-gradient( center top, #3669c2 5%, #5ac5fa 100% );
                                        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#3669c2', endColorstr='#5ac5fa');
                                        background-color:#3669c2;
                                    }.tweetbutton:active:enabled {
                                        position:relative;
                                        bottom:1px;
                                    }.tweetbox{
                                        resize: vertical;
                                        font-size: 12px;
                                        height: 60px;
                                        border-radius:6px;
                                        border:3px solid #b8b8b8;
                                        width:280px;
                                    }.number:disabled{
                                        -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        box-shadow:inset 0px 1px 0px 0px #ffffff;
                                        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f0f0f0), color-stop(1, #f0f0f0) );
                                        background:-moz-linear-gradient( center top, #f0f0f0 5%, #f0f0f0 100% );
                                        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f0f0f0', endColorstr='#f0f0f0');
                                        background-color:#000000;
                                        -moz-border-radius:6px;
                                        -webkit-border-radius:6px;
                                        border-radius:6px;
                                        border:1px solid #4a569e;
                                        display:inline-block;
                                        color:#E41212;
                                        font-family:arial;
                                        font-size:15px;
                                        font-weight:bold;
                                        float: left;
                                        padding:6px 24px;
                                        text-decoration:none;
                                    }.Notification{
                                        font-size: 19px;
                                        height: 30px;
                                        text-align:center;
                                    }
                                </style>
                                <?php
                                $url = $this->Html->Url(array('controller' => 'Posts', 'action' => 'TweetReply'));
                                echo $this->Form->textarea('Text', array("cols" => 5, "id" => "TweetText", "placeholder" => "Compose new Tweet...", "class" => "tweetbox", "onkeydown" => "displayResult('" . '' . "')", "onkeyup" => "displayResult()", "onselect" => "displayResult()", "onchange" => "displayResult()"));
                                echo $this->Form->input('ReplyID', array('id' => 'ReplyID', 'type' => 'hidden'));
                                echo $this->Form->input('connect', array('id' => 'connect', 'type' => 'hidden'));
                                echo $this->Form->input('ReplyName', array('id' => 'ReplyName', 'type' => 'hidden'));
                                echo $this->Form->button('Tweet', array('id' => 'TweetButton', 'disabled' => 'disabled', 'class' => 'tweetbutton', 'onclick' => "send('" . $url . "')", 'type' => 'button'));
                                echo $this->Form->button('Cancel', array('id' => 'CancelReply', 'class' => 'tweetbutton', 'type' => 'button', "onclick" => "Cancel()"));
                                echo $this->Form->button('140', array('id' => 'x', 'class' => 'number', 'value' => '140', 'disabled' => 'disabled'));
                                ?>
                                <?php echo $this->Form->input('.', array("id" => "image", "class" => "tweetbox", "type" => "file")); ?>
                                <li><a href="/Tweets/upload_image">Upload an Image</a></li>
                                <?php echo $this->fetch('content1'); ?>
                            </div><!--span3-->



                            <div class="span6">
                                <div id = "Test" class = "Notification" ></div>

                                <?php echo $this->Session->flash(); ?>
                                <?php echo $this->Session->flash('auth'); ?>
                                <?php echo $this->fetch('content'); ?>
                                <?php echo $this->fetch('content2'); ?>
                                <?php echo $this->fetch('content3'); ?>

                            </div><!--span6-->

                            <div class="span3 offset4">
                                <div class="well pull-right">
                                    <ul class="nav nav-list">
                                        <li class="nav-header">
                                            Filters
                                        </li>
                                        <li><?php echo $this->Html->link('All filters', array('controller' => 'Posts', 'action' => 'allfilters')); ?></li>
                                        <li><?php echo $this->Html->link('Filter tweets by User', array('controller' => 'Users', 'action' => 'viewUsers')); ?></li>
                                        <li><?php echo $this->Html->link('Filter by account', array('controller' => 'Accounts', 'action' => 'filteraccount')); ?></li>
                                        <li><?php echo $this->Html->link('Filter DMs by account', array('controller' => 'Accounts', 'action' => 'viewClients')); ?></li>
                                        <li class="nav-header">
                                            Accounts
                                        </li><?php for ($i = 0; $i < count($accounts); $i++) { ?>  <?php
                                    echo $this->Form->create('tattlrAccount', array('action' => 'selectAccount'));
                                    echo $this->Form->hidden('Account', array('value' => $accounts[$i]));
                                    if ($currentlySelectedAccount == $accounts[$i]) {
                                        ?><li class="act1"><?php } else { ?><li class="act"><?php } ?> <?php
                                        echo $this->Form->submit($images[$i]) . "" . $accounts[$i];
                                        echo $this->Form->end();
                                    ?> </li> <?php
                                            }
                                ?>
                                    </ul>
                                </div>
                            </div><!--span3-->
                        </div><!--row-->
                    </div>
                    <script type="text/javascript">
                        $(document).ready(function() {
                            $.ajaxSetup({
                                cache: true
                            });
                            
                            //Loading Image.
                            var ajax_load = "<img src='http://d2o0t5hpnwv4c1.cloudfront.net/412_ajaxCalls/DEMO/img/load.gif' alt='loading...' style='top:48%; left:48%; position:relative;'/>";
                            
                            //PHP file URL.
                            var loadUrl = "/Posts/index";
                            var loadUrl2 = "/Posts/fetchHome";
                            var loadUrl3 = "/accounts/getFollowers";
                            
                            $(document).on("click", "#dash", function(){ 
                                $(".container-fluid2").html(ajax_load);  
                                $.get(  
                                loadUrl,  
                                {language: "php", version: 5},  
                                function(responseText){  
                                    $(".container-fluid2").html(responseText);
                                    $("#CancelReply").hide();
                                    history.replaceState(null, "Dashboard", "/posts");
                                    $(document).attr('title','Dashboard');
                                },  
                                "html"  
                            ); 
                            });
                            $(document).on("click", "#home", function(){ 
                                $(".container-fluid2").html(ajax_load);  
                                $.get(  
                                loadUrl2,
                                {language: "php", version: 5},  
                                function(responseText){  
                                    $(".container-fluid2").html(responseText);
                                    $("#CancelReply").hide();
                                    history.replaceState(null, "Timeline", "/posts/fetchHome");
                                    $(document).attr('title','Timeline');
                                },  
                                "html"  
                            );  
                            });  
                            $(document).on("click", "#followers", function(){
                                $(".container-fluid2").html(ajax_load);  
                                $.get(  
                                loadUrl3,  
                                {language: "php", version: 5},  
                                function(responseText){  
                                    $(".container-fluid2").html(responseText); 
                                    $("#CancelReply").hide();
                                    history.replaceState(null, "View followers", "/accounts/getFollowers");
                                    $(document).attr('title','Followers');
                                },  
                                "html"  
                            );  
                            });  
                        });  
                    </script>
                </body>
                <footer>
                    <?php echo $this->element('sql_dump'); ?>
                </footer>
                <?php echo $this->Facebook->init(); ?>
                </html>
